<?php

use App\Models\User;
use App\Models\GoldSeed;
use App\Models\GoldRound;
use App\Services\UserUpgrade\UserUpgrade;
use App\Services\MockUser\StormReclaimer;
use App\Services\MockUser\StormTerminator;
use App\Services\GoldStormTimer\GoldStormTimer;
use App\Services\UsersBatchHandler\UsersBatchHandler;

if (! function_exists('users_batch_handler')) {
	function users_batch_handler(Closure $closure, $scope = 'vip') {
		app(UsersBatchHandler::class)->run($closure, $scope);
	}
}

if (! function_exists('user_upgrade')) {
	function user_upgrade(User $user) {
		app(UserUpgrade::class)->upgrade($user);
	}
}

if (! function_exists('gold_storm_timer')) {
	function gold_storm_timer() {
		return app(GoldStormTimer::class)();
	}
}

if (! function_exists('gold_round_cache')) {
	/**
	 * @return GoldRoundCache|\Illuminate\Contracts\Foundation\Application|mixed
	 */
	function gold_round_cache($round) {
		return app(GoldRoundCache::class, ['round' => $round]);
	}
}

if (! function_exists('gold_rounds_cache')) {
	/**
	 * @return GoldRoundsCache|\Illuminate\Contracts\Foundation\Application|mixed
	 */
	function gold_rounds_cache() {
		return app(GoldRoundsCache::class);
	}
}

if (! function_exists('lock_rounds_cache')) {
	/**
	 * @return LockRoundsCache|\Illuminate\Contracts\Foundation\Application|mixed
	 */
	function lock_rounds_cache($round = null) {
		return app(LockRoundsCache::class, ['round' => $round]);
	}
}

if (! function_exists('reclaimer')) {
	/**
	 * @param $round
	 * @return StormReclaimer|\Illuminate\Contracts\Foundation\Application|mixed
	 */
	function reclaimer($round) {
		$round = ($round instanceof GoldRound) ? $round : GoldRound::find((int)$round);
		return app(StormReclaimer::class, ['round' => $round]);
	}
}

if (! function_exists('terminator')) {
	/**
	 * @param $round
	 * @return StormTerminator|\Illuminate\Contracts\Foundation\Application|mixed
	 */
	function terminator($round) {
		return app(StormTerminator::class, ['round' => $round]);
	}
}

if (! function_exists('has_locking_gold_round')) {
	function has_locking_gold_round(): bool {
		foreach (GoldRound::all() as $round) {
			if ($round->is_locking) {
				return true;
			}
		}
		return false;
	}
}
